﻿using EasyDDD.AdminModule.Domain.AggregateSysAdminRole;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyDDD.AdminModule.Application.CommandsSysAdminRole
{
    [AutoMapperTo(typeof(SysAdminRole))]
    public record SysAdminRoleSetStatusCommand : ICommand<SysAdminRole>
    {
        public Guid Id { get; set; }
        public Guid RowVersion { get; set; } = default!;
        public short Status { get; set; } = default!;
    }
    public class SysAdminRoleSetStatusCommandHandler(
         //IMapper mapper,
         Repository.SysAdminRoleRepository repository,
         ILogger<SysAdminRoleSetStatusCommandHandler> logger)
         : ICommandHandler<SysAdminRoleSetStatusCommand, SysAdminRole>
    {
        public async Task<SysAdminRole> Handle(SysAdminRoleSetStatusCommand request, CancellationToken cancellationToken)
        {
            logger.LogDebug("命令 SysAdminRoleSetStatusCommandHandler");
            var entity = await repository.GetAsync(request.Id, request.RowVersion);
            entity.SetStatus(request.Status);
            return entity;
        }
    }
}
